<?php
ini_set('max_execution_time', 0);
ini_set('register_globals', 1);
  
error_reporting(0);
ini_set('display_errors', 0 );
session_start();
//$con = mysql_connect("localhost","root","123");
$con = mysql_connect("localhost","root","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("gii", $con);
//mysql_query("SET NAMES utf8");
//mysql_query("SET CHARACTER_SET utf8");

// Formata data aaaa-mm-dd para dd/mm/aaaa
function databr($datasql) {
	if (!empty($datasql)){
	$p_dt = explode('-',$datasql);
	$data_br = $p_dt[2].'/'.$p_dt[1].'/'.$p_dt[0];
	return print $data_br;
	}
}
 
// Formata data dd/mm/aaaa para aaaa-mm-dd
function datasql($databr) {
	$str = str_replace("/", " ",$databr);
	if (!empty($str)){
	$p_dt = explode(' ',$str);
	if(count($p_dt)>=4){
	$data_sql = $p_dt[2].'-'.$p_dt[1].'-'.$p_dt[0] ." ".$p_dt[3] ;
	}else{
	$data_sql = $p_dt[2].'-'.$p_dt[1].'-'.$p_dt[0];
	}
	return $data_sql;
	}
}

//echo datasql("03/01/01");

function request($item){
	if(isset($_REQUEST[$item])){
		return $_REQUEST[$item];
		}else{
		return "";
		}
}
function text($item){
	if($item!=""){
		return "$item ";
	}else{
		return "";
	}
}






function mask($val, $mask)
{
 $maskared = '';
 $k = 0;
 for($i = 0; $i<=strlen($mask)-1; $i++)
 {
 if($mask[$i] == '#')
 {
 if(isset($val[$k]))
 $maskared .= $val[$k++];
 }
 else
 {
 if(isset($mask[$i]))
 $maskared .= $mask[$i];
 }
 }
 return $maskared;
}
function maskb($val){
$saida = substr("0000000000$val", -10);  
//$saida = substr("$val", -10);  
return $saida;
}
function arcolor($n,$d){
	$saida = round($n, $d);
	if ($saida>=0){
		return '<b style="color:#00ff00">'. $saida .'</b>' ;
	}else{
		return '<b style="color:#ff0000">'. $saida .'</b>' ;
	}
}




?>